﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VAdvantage.Classes;
using VAdvantage.Common;
using VAdvantage.Process;
using VAdvantage.Model;
using VAdvantage.DataBase;
using VAdvantage.SqlExec;
using VAdvantage.Utility;
using System.Windows.Forms;
using VAdvantage.Controls;
using System.Data;
using System.Data.SqlClient;
using VAdvantage.Logging;
using VAdvantage.Model;
using VAdvantage.ProcessEngine;

namespace VAdvantage.Process
{
    public class CommissionCopy : SvrProcess
    {
        /**	From Commission			*/
        private int _C_Commission_ID = 0;
        /** To Commission			*/
        private int _C_CommissionTo_ID = 0;

        /// <summary>
        /// Prapare - e.g., get Parameters.
        /// </summary>
        protected override void Prepare()
        {
            ProcessInfoParameter[] para = GetParameter();
            for (int i = 0; i < para.Length; i++)
            {
                String name = para[i].GetParameterName();
                if (para[i].GetParameter() == null)
                    ;
                else if (name.Equals("C_Commission_ID"))
                    _C_Commission_ID = para[i].GetParameterAsInt();
                else
                    log.Log(Level.SEVERE, "prepare - Unknown Parameter: " + name);
            }
            _C_CommissionTo_ID = GetRecord_ID();
        }

        /// <summary>
        /// Process - copy
        /// </summary>
        /// <returns>message</returns>
        protected override String DoIt()
        {
            log.Info("doIt - C_Commission_ID=" + _C_Commission_ID + " - copy to " + _C_CommissionTo_ID);
            MCommission comFrom = new MCommission(GetCtx(), _C_Commission_ID, Get_TrxName());
            if (comFrom.Get_ID() == 0)
                throw new Exception("No From Commission");
            MCommission comTo = new MCommission(GetCtx(), _C_CommissionTo_ID, Get_TrxName());
            if (comTo.Get_ID() == 0)
                throw new Exception("No To Commission");

            //
            int no = comTo.CopyLinesFrom(comFrom);
            return "@Copied@: " + no;
        }
    }
}
